 <template>
    <div>
        <div class="e-form">
            <BillTop @cancel="handleClose"></BillTop>
            <div class="tabs" style="margin-bottom: 120px">
                <div class="tabs-title">基本信息</div>
                <div style="width: 100%" class="form">
                    <el-form :model="basicForm" :label-width="formLabelWidth"
                       ref="ruleForm"
                             :rules="rules"
                             class="demo-ruleForm"
                    >
                        <el-row>
                            <el-col :span="12">
                               <el-form-item label="所属机构：">
                                    <span>{{ basicForm.orgName }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">

                                  <el-form-item label="汇总日期：" prop="summaryDate">
                                      <span v-if="isRedSingle">
                                    {{
                                        basicForm.summaryDate
                                    }}
                                </span>
                                           <el-date-picker
                                              v-else
                                            value-format="yyyy-MM-dd"
                                            :clearable="false"
                                            type="date"
                                            placeholder="选择日期"
                                            v-model="basicForm.summaryDate"
                                        ></el-date-picker>

                                </el-form-item>
                            </el-col>

                            <el-col :span="12">
                                <el-form-item label="录入人：">
                                <span>
                                    {{
                                        basicForm.inputName
                                    }}
                                </span>
                                </el-form-item>
                            </el-col>

                        </el-row>
                           <!-- <el-row>
                            <el-col :span="12">
                                    <el-form-item label="摊销金额：">
                                            <span>{{
                                               basicForm.amount
                                            }}</span>
                                        </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="报销数量：">
                                <span>
                                    {{
                                        basicForm.quantity
                                    }}
                                </span>
                                </el-form-item>
                            </el-col>

                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="录入人：">
                                <span>
                                    {{
                                        basicForm.inputName
                                    }}
                                </span>
                                </el-form-item>
                            </el-col>

                        </el-row> -->

                    </el-form>
                </div>
            </div>
            <div class="buttons">
                <span class="tip"><span style="color: red; margin-right: 0">*</span>为必填项</span>

                <el-button
                    type="primary"
                    size="small"
                    style="background: #2e61d7"
                    @click="addSave"
                    >保存</el-button
                >
                <el-button size="small" @click="handleClose">取消</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import { turnoverAmortizationGetAmortization } from '@/api/turnover/ppw.js'
import otherRequest from '@/api/turnover/other.js'
export default {
    data () {
        return {
            //基础信息
            basicForm: {
                'amortizationBill': [
                    {
                        'amortizationId': '',
                        'amortizationNo': ''
                    }
                ],
                'amount': 0,
                'billId': '',
                'billNo': '',
                'inputId': '',
                'inputName': '',
                'isShare': 0,
                'nullifyCreated': '',
                'nullifyCreator': '',
                'nullifyCreatorId': '',
                'nullifyDescription': '',
                'nullifyReason': '',
                'orgId': '',
                'orgName': '',
                'parentId': '',
                'quantity': 0,
                'redState': -1,
                'remarks': '',
                'state': 0,
                'summaryDate': '',
                'workId': ''
            },
            formLabelWidth: '180px',
            currencyArr: [], //币种列表
            stateArr: ['草稿', '审核中', '已审核', '已作废'],
            rules: {
                summaryDate: [
                    {
                        required: true,
                        message: '选择日期',
                        trigger: 'change'
                    }
                ]
            },
            yearNeedPlanList: [],
            isRedSingle: false,
            amortizationIdArr: [],

        }
    },
    created () {
        this.getUserInfo()
        this.$route.query.isRedSingle === '1' ? this.isRedSingle = true : this.isRedSingle = false
        if (this.isRedSingle) {
            this.getRedList()
        }
    },

    methods: {
        // 如果是点击冲红单进入的新增页,则需要返显数据,只有备注能修改,其余均不能修改
        async getRedList () {
            let data = await otherRequest.turnoverAmortizationSummaryInit(this.$route.query.billid)
            this.basicForm = data
        },
        //获取本地登录信息
        getUserInfo () {
            const userInfo = JSON.parse(window.localStorage.getItem('vuex')).userInfo.orgInfo
            const userName = window.localStorage.getItem('userName')
            const userId = window.localStorage.getItem('userId')
            this.basicForm.inputName = userName
            this.basicForm.inputId = userId

            this.basicForm.orgId = userInfo.orgId
            this.basicForm.orgName = userInfo.orgName
        },
        selectBtn () {
            turnoverAmortizationGetAmortization().then(res=>{
                this.basicForm.amortizationBill = res.amortizationBill
                this.basicForm.amount = res.amount
                this.basicForm.quantity = res.quantity
                if(this.basicForm.amortizationBill.length > 0) {
                    this.amortizationIdArr = this.basicForm.amortizationBill.map(item=>item.amortizationId )
                    this.postSummaryDtl()
                }
            })
        },
        // 汇总明细
        postSummaryDtl () {

            otherRequest.turnoverAmortizationSummarySummaryDtl({
                'billId': this.billId,
                'billIds': this.amortizationIdArr
            }).then(()=>{
                this.clientPop(
                    'suc',
                    '汇总明细成功',
                    this.getDtlList
                )
            })
        },
        //基本信息保存
        addSave () {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    this.$Ajax
                        .httpPost({
                            url: '/turnover/amortizationSummary/create',
                            params: this.basicForm
                        })
                        .then(res => {
                            this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                                this.$router.push({
                                    path: '/revolveAmortizationSummaryEdit',
                                    query: {
                                        billid: res,
                                        name: 'detailed'
                                    }
                                })
                            },
                            null,
                            this.handleClose
                            )
                        })
                }
            })
        },
        //取消
        handleClose () {
            this.$router.push('/revolveAmortizationSummaryList')
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
.e-table {
    min-height: auto;
    background: #fff;
}
.separ {
    width: 30px;
    height: 40px;
    line-height: 18px;
    text-align: center;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
::v-deep.el-table .cell {
    text-align: center;
}
</style>
